package work.shyk.kongMonitor.dto.param;

import com.google.common.collect.ImmutableMap;
import work.shyk.kongMonitor.dto.param.interfaces.MustQuery;

import java.util.ArrayList;
import java.util.List;

/**
 * description: <br>
 * createTime: 2021/3/24 15:09 <br>
 *
 * @author zzh
 */
public class EsAggsQueryBuilder {
    EsAggsQuery esAggsQuery;

    List<MustQuery> list = new ArrayList<>();

    List<AbstractAggsQuery> aggsQueryList = new ArrayList<>();

    public EsAggsQueryBuilder() {}

    public EsAggsQueryBuilder newEsSearch() {
        return this;
    }

    public EsAggsQueryBuilder addWildcardQuery(String key, String value) {
        list.add(new WidcardQuery(ImmutableMap.<String, String> builder()
                .put(key, value).build()));
        return this;
    }

    public EsAggsQueryBuilder addRangeQuery(String field, long minValue, long maxValue) {
        list.add(new RangeQuery(field, new Range(minValue, maxValue)));
        return this;
    }

    public EsAggsQueryBuilder addAggs(AbstractAggsQuery aggsQuery) {
        this.aggsQueryList.add(aggsQuery);
        return this;
    }

    public EsAggsQuery build() {
        esAggsQuery = new EsAggsQuery(list, aggsQueryList);
        return esAggsQuery;
    }
}
